﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson8 : MonoBehaviour
{
    //线性插值
    public Transform A;
    public Transform B;
    //球形插值
    public Transform C;

    public Transform target;

    public Vector3 startPos;
    public float time;
    public Vector3 nowTarget;
    void Start()
    {
        startPos = B.position;
        nowTarget = target.position;
    }

    // Update is called once per frame
    void Update()
    {
        #region 知识点一 线性插值
        //result = start + (end - start) * t;

        //1.先快后慢 每帧改变start位置 位置无限接近 但不会得到end位置
        A.position = Vector3.Lerp(A.position, target.position, Time.deltaTime);

        //2.匀速 每帧改变时间 当t>=1时 得到结果
        if (nowTarget  != target.position)
        {
            nowTarget = target.position;
            time = 0;
            startPos = B.position;
        }
        time += Time.deltaTime;
        B.position = Vector3.Lerp(startPos, target.position, time);
        #endregion

        #region 知识点二 球形插值
        C.position = Vector3.Slerp(Vector3.right * 10, Vector3.forward * 10, time * 0.3f);
        #endregion
    }
}
